package thinkingJava.chapter14;

import java.util.HashMap;

public class PetCount {
	static class PetCounter extends HashMap<String, Integer> {
		public void count(String type) {
			Integer quantity = get(type);
			if (quantity == null) {
				put(type,1);
			} else {
				put(type,quantity + 1);
			}
		}
	}
	public static void countPets(PetCreater creator) {
		PetCounter pc = new PetCounter();
		for (Pet pet : creator.createArray(20)) {
			System.out.print(pet.getClass().getSimpleName() + "    ");
			if (pet instanceof Pet) {
				pc.count("Pet");
			}
			if (pet instanceof Mutt) {
				pc.count("Mutt");
			}
			if (pet instanceof Dog) {
				pc.count("Dog");
			}
			if (pet instanceof Manx) {
				pc.count("Manx");
			}
			if (pet instanceof Hamster) {
				pc.count("Hamster");
			}
			if (pet instanceof Mouse) {
				pc.count("Mouse");
			}
			if (pet instanceof Rat) {
				pc.count("Rat");
			}
			if (pet instanceof Rodent) {
				pc.count("Rodent");
			}
			if (pet instanceof EgyptianMau) {
				pc.count("EgyptianMau");
			}
		}
		System.out.println();
		System.out.println(pc);
	}
	public static void main(String[] args) {
		countPets(new ForNameCreater());
	}
}
